#coding: utf-8
import re

SR2SQLMAPPINGS = {
    u'Конечный пункт':'destination',
    u'Дата': 'date'
}

ADJECTIVES_TO_PREPOSITION = [
    u'дороже',
    u'дешевле'

]

ANTONYMS_DICTIONARY={
    u'дороже': u'дешевле',
    u'дешевле': u'дороже',
    u'больше': u'меньше',
    u'меньше': u'больше'
}

def remove_non_alphanumeric(text):
    """
    Returns string with only alphanumeric characters remained

    Keyword arguments:
    text -- string which would be processed
    """
    pattern = re.compile('[\W_]+')
    return pattern.sub('', text)



def skim_semantic_representations(tree, entities):
    """
        Returns top-level semantic representations from a tree
    """
    fetched_entities = []
    try:
        fetched_entities.append(entities[tree])
    except KeyError:
        for child in tree:
            fetched_entities.extend(skim_semantic_representations(child, entities))
    return fetched_entities

def ask_clarification(question, question_argument=None, options = None ):
    """
        Promts the user to select one of several options

        Keyword arguments:
        question -- question that is above options to select
        question_argument -- argument that can be put in the end of question
        options -- list of options
    """
    if question_argument:
        question += question_argument + '?'
    print question
    print '================================================='
    index = 1
    for option in options:
        print '\t' + str(index) + ': ', option
        index += 1
    input_text = raw_input('Введите номер соответствующего элемента: ')
    return input_text

def is_digit(string):
    try:
        int(string)
        return True
    except ValueError:
        return False

def br(string):
    return "'" + string + "'"

def get_elements_that_are_matched_in_string(elementslist, search_body_string):
    return [element for element in elementslist if element in search_body_string]
#above function test
#print get_elements_that_are_matched_in_string(['ab','cd'],'fabcdx')

def str2int(string):
    return int(remove_non_alphanumeric(string))

def separate_concept( semantic_representation):
    modifiers = []
    parts = semantic_representation.split('*')
    for p in parts[1:]:
        modifiers.append(separate_modifier(p))
    return parts[0], modifiers



def separate_modifier( semantic_representation):
    parts = map(lambda x: x.lstrip('(').rstrip(')'),semantic_representation.split(','))
    return parts

class SEMANTIC_ENTITIES:
    DAY = u'день'
    NUMBER = u'число'

class CLARIFICATION_QUESTIONS:
    BASEFORM = u'Какая базовая форма соответствует слову '
    GRAMINFO = u'К какой части речи относится слово '
    NOUN_NOUN_RELATIONSHIP = u'Какое из семантических отношений реализуется в сочетании: '
    VERB_NOUN_RELATIONSHIP = u'Какое из семантических отношений реализуется в сочетании: '


#SETTINGS PARAMETER
PYMORPHY_DICTIONARIES_PATH = """/home/love/Desktop/sema/data/dics/"""

class POS_TAGS:
    ADJECTIVE = 'ADJ'
    ADVERB = 'ADV'
    CONJUNCTION = 'CNJ'
    COUNTABLE_NUMERAL = 'NC'
    DEEPRICHASTIE = 'DP'
    #FOR COMMAS, QUESTION MARKS, ETC
    DELIMETER = 'DEL'
    INTERJECTION = 'UH'
    NOUN = 'N'

    ORDINAL_NUMERAL = 'NO'
    PREPOSITION ='P'
    PRICHASTIE = 'PR'
    PRONOUN = 'PRO'
    PROPER_NOUN = 'NP'
    VERB = 'V'
    NUMBER = 'NB'
    NOT = 'NOT'

class TENSES:
    PRESENT = 'PRS'
    PAST = 'PST'
    FUTURE = 'FT'

class GRCASES:
    IMENITELNYI = 'NOM'
    RODITELNYI = 'GEN'
    DATELNYI = 'DAT'
    VINITELNYI = 'ACC'
    TVORITELNY = 'INS'
    PREDLOZHNYI = 'LOC'

class NUMBER:
    SINGULAR = 'SG'
    PLURAL = 'PL'

class GEN:
    MALE = 'M'
    FEMALE = 'F'
    SREDNIY = 'N'

class VOICE:
    ACTIVE = 'ACT'
    PASSIVE = 'PASS'

class TABLE_NAMES:
    LSD = 'lsd'
    DPF = 'dpf'
    DVPF = 'Dvpf'

class DPF_FIELDS_NAMES:
    PREPOSITION = 'prep'
    FIRST_SORT = 'sort1'
    SECOND_SORT = 'sort2'
    GRAMMAR_CASE = 'grcase'

class DVPF_FIELDS_NAMES:
    PREPOSITION = 'preposition'
    SORT = 'str'
    SEMANTIC_ENTITY = 'semsit'
    GRAMMAR_CASE = 'grcase'

class LOGICAL_OPERATORS:
    AND = u'И'
    OR = u'ИЛИ'
    NOT = u'НЕ'